//
//  COBaseController.swift
//  CocoProject
//
//  Created by Vill on 2023/11/2.
//

import UIKit

class COBaseController: UIViewController {
    
    override var title: String?{
        didSet{
            self.titleLabel.text = title
        }
    }
    
    lazy var navView: UIView = {
        let nav = UIView()
        nav.backgroundColor = .clear
        return nav
    }()

    lazy var titleLabel : UILabel = {
        let label = UILabel.init()
        label.font = UIFont.pingfangFont(ofSize: PTW(18), weight: .semibold)
        label.textColor = UIColor.white
        return label
    }()

    // 返回按钮
    lazy var fanhuiBtn: UIButton = {
        let fanhui = UIButton()
        fanhui.setImage(KImaged("coco_base_fanhui"), for: .normal)
        fanhui.addTarget(self, action: #selector(fanhuiAction), for: .touchUpInside)
        return fanhui
    }()
    
    lazy var bgImg: UIImageView = {
        let nav = UIImageView()
        nav.image = KImaged("coco_main_bg")
        nav.contentMode = .scaleAspectFill
        nav.clipsToBounds = true
        return nav
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        xl_prefersNavigationBarHidden = true
        xl_interactivePopMaxAllowedInitialDistanceToLeftEdge = PTW(200)
        self.view.addSubview(self.bgImg)
        self.bgImg.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    @objc func fanhuiAction(){
        self.navigationController?.popViewController(animated: true)
    }
    
    // 添加导航栏
    func addnav(){
        view.addSubview(navView)
        navView.addSubview(fanhuiBtn)
        navView.addSubview(titleLabel)
        navView.snp.makeConstraints { make in
            make.leading.top.trailing.equalToSuperview()
            make.height.equalTo(KStatusAndNavBarHeight)
        }
        fanhuiBtn.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(PTW(10))
            make.size.equalTo(PTW(44))
            make.bottom.equalToSuperview()
        }
        titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalTo(fanhuiBtn)
        }
    }
}
